<?php


class Contact_Home_Controller extends Base_Controller
{

	public $restful = true;


	public function __construct()
	{
		parent::__construct();
		//--Your Code --//
		$this->theme->set_theme("default") ;
		$this->theme->set_layout("column1") ;
	}


	public function get_index()
	{
		$data['purpose'] = Config::get('Contact::config.purpose');
		$this->theme->title(Config::get('Contact::config.meta_title'));
		$this->theme->keyword(Config::get('Contact::config.meta_keyword'));
		$this->theme->description(Config::get('Contact::config.meta_description'));

		$data['title'] = "Contact Us";
		$this->theme->title($data['title'].' - '.Settings::get('en','site_title'));
		/*-- BREADCRUMB */
		 
		Breadcrumb::addbreadcrumb('Home', URL::base());
		Breadcrumb::addbreadcrumb('Contact Us', URL::base());
		Breadcrumb::setSeparator('&raquo;');
		$data['breadcrumb'] = Breadcrumb::generate();
		return $this->theme->render('Contact::index', $data);
	}

	public function post_index()
	{
		$rules = array(
				//'contact_name' => 'required|min:4',
				//'purpose' => 'required',
				'contact_email' => 'required|email',
				//'conatct_no' => 'required',
				//'contact_description' => 'required|min:25'
		);


		$v = Validator::make(Input::all(), $rules);

		if ($v->fails()) {
			//https://m
			$response = array(
					'status' => 'Fail',
					'message' => '<div class="alert alert-danger">Invalid Input..</div>',
			);
		} else {
			 
			 
			$data = array(
					'title' => Config::get('Contact::config.title'),
					'contact_name' => trim(Input::get('contact_name')),
					'purpose' => trim(Input::get('purpose')),
					'contact_email' => trim(Input::get('contact_email')),
					'conatct_no' => Input::get('conatct_no'),
					'contact_description' => Input::get('contact_description'),

			);

			
		}

		$emailTemp = DB::table('emailtemplate')->where('variable','=','contact_us')->first();
				
				
				$temTitle = $emailTemp->title;
				$temDesc = $emailTemp->description;
				
				$webTitle = Settings::get('en','site_title');
				$body = array(
						'website_title' => "<a href='".URL::base()."'>$webTitle</a>",
						'name' => trim(Input::get('contact_name')),
						'purpose' => trim(Input::get('purpose')),
						'email' => trim(Input::get('contact_email')),
						'contact_no' => trim(Input::get('conatct_no')),
						'description' => Input::get('contact_description'),
				);
				
				
				$footer = Settings::get('en','mail_smtp_footer');
				
				
				$description = Parser::parse_string($temDesc, $body,TRUE);
				
				$description .= "<p>$footer</p>";
			
				$p = array(
						'from' => trim(Input::get('contact_email')),
						'to' => Settings::get('en','default_email'),
						'sender_name' => trim(Input::get('contact_name')),
						'reply_to' => 'noreply@gmail.com',
						'subject' => trim($temTitle),
						'body' => trim($description),
						
				);
				
				//dd($p);
				Commoncall::mail($p);
				
			
		return Redirect::back()->with('message', '<div class="alert alert-info">Done..</div>');
	}




	//--//

	 

	//--Send mail to Message Sender--//
	 

	//--//



	 









}

